package com.mashibing.webmaster.service.impl;

import com.mashibing.webmaster.entity.ClientBusiness;
import com.mashibing.webmaster.entity.ClientBusinessExample;
import com.mashibing.webmaster.mapper.ClientBusinessMapper;
import com.mashibing.webmaster.service.ClientBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author SNA
 * @date 2025/10/27
 * @Description
 **/
@Service
public class ClientBusinessServiceImpl implements ClientBusinessService {

    @Autowired
    private ClientBusinessMapper clientBusinessMapper;

    /**
     * 查询所有客户信息
     *
     * @return
     */
    @Override
    public List<ClientBusiness> findAll() {
        List<ClientBusiness> list = clientBusinessMapper.selectByExample(null);
        return list;
    }

    /**
     * 根据用户id查询客户信息
     *
     * @param userId
     * @return
     */
    @Override
    public List<ClientBusiness> findByUserId(Integer userId) {
        //1、封装查询条件
        ClientBusinessExample example = new ClientBusinessExample();
        // 创建一个 ClientBusinessExample.Criteria 对象。
        // Criteria 是MyBatis Generator生成的内部类，用于构建查询条件。每个 Criteria 对象代表一组AND连接的查询条件
        /*
            这是一个链式调用方法，用于添加查询条件
            方法名遵循特定命名规则：and + 字段名 + 操作符
            具体含义：添加一个条件，要求 extend1 字段等于传入的 extend1 参数值
            生成的SQL类似：WHERE extend1 = ?
         */
        example.createCriteria().andExtend1EqualTo(userId + "");
        List<ClientBusiness> list = clientBusinessMapper.selectByExample(example);
        return list;
    }
}
